def pr(n):
    for b in range(2, int(n ** 0.5) + 1):
        if n % b == 0:
            return False
    return True


v = input().split()
w = {
    "zero": "0", "one": "1", "two": "2", "three": "3", "four": "4", "five": "5", "six": "6", "seven": "7", "eight": "8",
    "nine": "9"
}
p = ""
d = True
for i in v:
    d = True
    for j in w:
        if j in w:
            if i == j:
                p += w[i]
        else:
            print("Wrong input")
            d = False
            break
    if not d:
        break
if d and len(p) == 3 and p[0] != "0":
    p = int(p)
    m = 0
    mm = 0
    for i in range(p, p + 11):
        if pr(i):
            m = i
            break
    for i in range(p - 1, p - 11, -1):
        if pr(i):
            mm = i
            break
    if m - p < p - mm:
        print(m)
    elif m - p > p - mm or m - p == p - mm:
        print(mm)
else:
    print("Wrong input")
